layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 调拨管理管理
     */
    var FruitsAllocation = {
        tableId: "fruitsAllocationTable"
    };

    /**
     * 初始化表格的列
     */
    FruitsAllocation.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {field: 'states', sort: true, title: '状态', style:'font-weight: 600;'},
            {field: 'times', sort: true, title: '时间', style:'font-weight: 600;'},
            {field: 'warehouseNameOut', sort: true, title: '调出仓库', style:'font-weight: 600;'},
            {field: 'warehouseNamePut', sort: true, title: '调入仓库', style:'font-weight: 600;'},
            {field: 'goodsId', sort: true, title: '商品id', hide: true},
            {field: 'goodsName', sort: true, title: '商品名称', totalRowText: '合计：', style:'font-weight: 600;'},
            {field: 'nweight', sort: true, title: '净重', totalRow: true, style:'font-weight: 600;'},
            {field: 'producetime', sort: true, title: '生产日期', style:'font-weight: 600;'},
            {field: 'userName', sort: true, title: '操作人', style:'font-weight: 600;'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    FruitsAllocation.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        table.reload(FruitsAllocation.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 导出excel按钮
     */
    FruitsAllocation.exportExcel = function () {
        var checkRows = table.checkStatus(FruitsAllocation.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + FruitsAllocation.tableId,
        url: Feng.ctxPath + '/fruitsAllocation/list',
        page: true,
        limit: 40,
        height: "full-60",
        toolbar: '#toolbarfrom',
        totalRow: true ,//开启合计行
        cellMinWidth: 100,
        cols: FruitsAllocation.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        FruitsAllocation.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        FruitsAllocation.exportExcel();
    });

    // 单击行事件
    table.on('row(' + FruitsAllocation.tableId + ')', function (obj) {
		$('div[lay-id="' + FruitsAllocation.tableId + '"]').find(".layui-table-body tr ").attr({ "style": "background:#FFFFFF" });//其他tr恢复原样
		$('div[lay-id="' + FruitsAllocation.tableId + '"]').find(obj.tr.selector).attr({ "style": "background:#e6e6e6" });//改变当前tr颜色
    });
});
